﻿using SuperMoney.Datas.DbModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperMoney.Datas.DbServices
{
	/// <summary>
	/// 全局设置Db服务
	/// </summary>
	public class GSettingDbService
	{
		/// <summary>
		/// 服务实例
		/// </summary>
		public static readonly GSettingDbService Instance = new GSettingDbService();

		/// <summary>
		/// 新初始化DB
		/// </summary>
		/// <returns></returns>
		MRMEntities NewDB()
		{
			return new MRMEntities();
		}

		/// <summary>
		/// 获取特定Key的全局设置项
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public GSetting GetGSetting(string key)
		{
			using (var db = this.NewDB())
			{
				return db.GSettingSet.Where(p => p.Key == key).SingleOrDefault();
			}
		}
	}
}
